package com.party.admin.task;

import com.party.admin.biz.merchantAnalyze.MemberMerchantCountBizService;
import com.party.admin.biz.merchantAnalyze.MemberMerchantDetailBizService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 机构数据刷新
 * Created by wei.li
 *
 * @date 2017/9/14 0014
 * @time 17:36
 */
@Component(value = "quartzMerchantAnalyze")
@RequestMapping("test/init")
public class QuartzMerchantAnalyze {

    @Autowired
    private MemberMerchantDetailBizService memberMerchantDetailBizService;

    @Autowired
    private MemberMerchantCountBizService memberMerchantCountBizService;

    protected static Logger logger = LoggerFactory.getLogger(QuartzMerchantAnalyze.class);

    /**
     * 刷新机构数据
     */
    public void refresh(){
        logger.info("开始刷新机构数据");
        try {
            synchronized (this){
                memberMerchantDetailBizService.today();
                memberMerchantCountBizService.init();
            }
        } catch (Exception e) {
            logger.error("刷新机构数据异常,", e);
        }
    }


    /**
     * 刷新机构昨天的数据
     */
    public void refreshYesterday(){
        logger.info("开始刷新机构前一天数据");
        try {
            memberMerchantDetailBizService.yesterday();
            memberMerchantCountBizService.init();
        } catch (Exception e) {
            logger.error("刷新机构前一天数据异常", e);
        }
    }

    /**
     * 初始化成功数
     */
    @RequestMapping("/test")
    public void initSuccessNum() {
        try {
            memberMerchantDetailBizService.initSuccessNum();
            memberMerchantCountBizService.initSuccessNum();
        } catch (Exception e) {
            logger.error("初始化机构成功数异常", e);
        }
        logger.info("初始化机构成功数结束");
    }
}
